<?php
/**
 * 账单
 */
namespace App\Validation;

use Phalcon\Validation\Validator\PresenceOf;
use Phalcon\Validation\Validator\Numericality;
use Phalcon\Validation\Validator\InclusionIn;

class BillSearchValidation extends BaseValidation
{
	public function initialize()
	{
		
		$this->add(
			"bill_type",
			new InclusionIn(
				  [
					  "field" => "bill_type",
					  "domain" => [0,1,2],//0,被打赏,1打赏,2付费报告
					  "message" => ":field is not included in 0 or 1 or 2",
					  "allowEmpty" => true,
				  ]
			)
		);

		$this->add(
			"pay_code",
			new InclusionIn(
				  [
					  "field" => "pay_code",
					  "domain" => ['weixi','qq','weibo'],
					  "message" => ":field is not included in weixi or qq or weibo",
					  "allowEmpty" => true,
				  ]
			)
		);

		$this->add(
			"title",
			new PresenceOf(
				  [
					  "message" => ":field is required",
					  "allowEmpty" => true,
				  ]
			)
		);

		$this->add(
			"nickname",
			new PresenceOf(
				  [
					  "message" => ":field is required",
					  "allowEmpty" => true,
				  ]
			)
		);

		$this->add(
			"bill_name",
			new PresenceOf(
				  [
					  "message" => ":field is required",
					  "allowEmpty" => true,
				  ]
			)
		);

		$this->add(
			"bn",
			new PresenceOf(
				  [
					  "message" => ":field is required",
					  "allowEmpty" => true,
				  ]
			)
		);

		$this->add(
			"min_amount",
			new Numericality(
				  [
					  "message" => ":field is not numeric",
					  "allowEmpty" => true,
				  ]
			)
		);

		$this->add(
			"max_amount",
			new Numericality(
				  [
					  "message" => ":field is not numeric",
					  "allowEmpty" => true,
				  ]
			)
		);

		$this->add(
			"p",
			new Numericality(
				  [
					  "message" => ":field is not numeric",
				  ]
			)
		);
		
		$this->add(
			"page_num",
			new Numericality(
				  [
					  "message" => ":field is not numeric",
				  ]
			)
		);
	}

	//验证之前
	public function beforeValidation($data, $entity, $messages)
    {
        parent::beforeValidation($data, $entity, $messages);
        
        return true;
    }
}